<template>
    <div class="box">
        <!-- tab切换 -->
        <div class="tabbar">
            <div class="tabItem" :class="choseTab == 0 ? 'choseColor' : ''" @click="changeTab(0)">
                系统公告
                <div v-if="choseTab == 0" class="line"></div>
            </div>
            <div class="tabItem" :class="choseTab == 1 ? 'choseColor' : ''" @click="changeTab(1)">
                个人公告
                <div v-if="choseTab == 1" class="line"></div>
            </div>
        </div>
        <!-- 消息列表 -->
        <!-- 系统公告 -->
        <div class="messItem" v-if="choseTab == 0 && messageList2.length !== 0">
            <div class="itemContent" @click="goNext(1,index)" v-for="(item, index) in messageList2" :key="item.id">
                <div class="isTime">{{ item.createTime }}</div>
                <div class="messContent">
                    <div class="messTit">
                        <div>{{ item.title }}</div>
                    </div>
                    <div class="content">{{ item.content }}</div>
                </div>
            </div>
        </div>
        <!-- 个人公告 -->
        <div class="messItem" v-else-if="choseTab == 1 && messageList1.length !== 0">
            <div class="itemContent" @click="goNext(1,index)" v-for="(item, index) in messageList2" :key="item.id">
                <div class="isTime">{{ item.createTime }}</div>
                <div class="messContent">
                    <div class="messTit">
                        <div>{{ item.title }}</div>
                    </div>
                    <div class="content">{{ item.content }}</div>
                </div>
            </div>
        </div>
        <div v-if="(choseTab == 0 && messageList2.length == 0) || (choseTab == 1 && messageList1.length == 0)" class="noMore">
            <img src="../../assets/images/noMessage.png" />
            <div>暂无公告~</div>
        </div>
    </div>
</template>

<script setup name="message">
import { appNotices, appNoticeInds } from '@/utils/api'
const route = useRouter()
const choseTab = ref(0)
const currentPage = ref(1)
const messageList1 = ref([])
const messageList2 = ref([])
// 切换tab栏
const changeTab = val => {
    choseTab.value = val
    currentPage.value = 1
    if (choseTab.value == 0) {
        appNotice()
    } else if (choseTab.value == 1) {
        appNoticeInd()
    }
}

// 跳往详情页
const goNext = (item,index) => {
    route.push(`/message/detail?index=${item}&type=${index}`)
}
// 获取系统公告
const appNoticeInd = () => {
    appNoticeInds({
        currentPage: currentPage.value
    }).then(res => {
        if (res.code == 200) {
            messageList1.value = res.object
        }
    })
}

// 获取个人公告
const appNotice = () => {
    appNotices({
        currentPage: currentPage.value
    }).then(res => {
        if (res.code == 200) {
            messageList2.value = res.object
            console.log(messageList2.value)
        }
    })
}
// 初始加载系统公告
appNotice()
</script>

<style scoped lang="scss">
.box {
    min-height: 100vh;
    background-color: #f5f5f5;
    .choseColor {
        color: #66d6ff !important;
    }

    .tabbar {
        display: flex;
        background: #fbfbfb;
        box-shadow: 0px 0px 6px rgba(0, 0, 0, 0.16);

        .tabItem {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
            flex: 1;
            height: 40px;
            opacity: 1;
            border-radius: 0rpx;
            font-size: 16px;
            font-family: SimHei;
            font-weight: 400;
            color: #848484;

            .line {
                width: 30px;
                height: 3px;
                background: #66d6ff;
                opacity: 1;
                border-radius: 2px;
                margin-top: 5px;
            }
        }
    }

    .messItem {
        margin-top: 12px;
        .itemContent {
            margin-top: 14px;
        }
        .isTime {
            text-align: center;
            font-size: 10px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #545454;
            opacity: 1;
        }

        .messContent {
            width: 88%;
            margin: 0 auto;
            line-height: 30px;
            padding: 10px;
            background-color: #fff;
            border-radius: 6px;
            margin-top: 7px;

            .messTit {
                display: flex;
                align-items: center;

                div {
                    font-size: 14px;
                    font-family: Microsoft YaHei;
                    font-weight: bold;
                    color: #545454;
                    opacity: 1;
                }
            }

            .content {
                font-size: 14px;
                font-family: Microsoft YaHei;
                font-weight: 400;
                color: #545454;
                opacity: 1;
                margin-top: 7px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }
        }
    }
    .noMore {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-top: 121px;
        font-size: 14px;
        img {
            width: 238px;
            height: 190px;
            margin-bottom: 20px;
        }
    }
}
</style>
